package com.etung.iot.demo.controller;

import com.etung.iot.demo.boxConfig.Box;
import com.etung.iot.demo.core.Authorized;
import com.etung.iot.demo.services.ProjectService;
import com.etung.iot.demo.vo.Result;
import com.etung.iot.demo.vo.req.ProjectReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/project")
@Api(tags = "项目接口")
public class ProjectController {
    @Autowired
    private ProjectService projectService;

    @Authorized
    @PostMapping("/create")
    @ApiOperation(value = "创建项目",response = Result.class)
    public Result <?> create(@RequestBody ProjectReq project){
        return Result.OK(projectService.saveProject(project));
    }

    @Authorized
    @PostMapping("/query")
    @ApiOperation(value = "查询项目",response = Result.class)
    public Result <?> query(@RequestBody ProjectReq project){
        return Result.OK(projectService.queryProject(project));
    }

    @Authorized
    @PostMapping("/update")
    @ApiOperation(value = "更新项目名称",response = Result.class)
    public Result <?> update(@RequestBody  ProjectReq project){
        projectService.updateProject(project);
        return Result.OK();
    }

    @Authorized
    @PostMapping("/delete")
    @ApiOperation(value = "删除项目",response = Result.class)
    public Result <?> del(@RequestBody ProjectReq project){
        projectService.delProject(project);
        return Result.OK();
    }

    @Authorized
    @PostMapping("/selectBox")
    @ApiOperation(value = "查询BOX列表",response = Result.class)
    public Result <?> selectBox(@RequestBody ProjectReq project){
        return Result.OK(projectService.selectBoxList(project));
    }
}
